---
title: Dify Plugin for Long-Term Memory
---

Enhance your Dify applications with long-term memory by integrating the Memobase plugin. This guide will walk you through setting up and using the plugin to create more intelligent, context-aware AI agents.

## Prerequisites

First, find and install the open-source [Memobase plugin](https://github.com/ACAne0320/dify-plugin-memobase) from the Dify plugin marketplace.

<Frame caption="Memobase Plugin in the Dify Marketplace">
  <img src="/images/dify_memobase_marketplace.png" />
</Frame>

Next, you'll need a Memobase instance:

-   **Memobase Cloud**: The easiest way to get started is by signing up for a managed instance on the [Memobase dashboard](https://www.memobase.io/en/dashboard).
-   **Self-Hosted**: For more control, you can deploy your own instance. See the [Memobase GitHub repository](https://github.com/memodb-io/memobase) for instructions.

## Plugin Configuration

To connect the plugin to your Memobase instance, you need to provide two credentials when adding the tool to your Dify application:

1.  **Memobase URL**: The API endpoint for your instance (e.g., `https://api.memobase.dev`).
2.  **Memobase API Key**: Your unique API key for authentication.

You can find both of these in your Memobase dashboard.

<Frame caption="API Key and URL in the Memobase Dashboard">
  <img src="/images/dify_memobase_dashboard.png" />
</Frame>

## Using the Plugin in Dify Workflows

Once configured, you can use the plugin's tools in your Dify workflows to:

-   **Store and Recall Conversations**: Persist dialogue for long-term context.
-   **Personalize Responses**: Retrieve user profiles to tailor interactions.
-   **Access Past Events**: Search and utilize historical user data.
-   **Manage Memory**: Directly manipulate data within your Memobase instance from Dify.

For detailed information on each tool, refer to the [Memobase API Reference](/api-reference/overview).

### Understanding Memobase's Buffer Mechanism

Memobase uses a **buffer system** to optimize processing costs and efficiency:

-   **Buffered Processing**: Messages are not processed immediately. Instead, they are stored in a user buffer until it reaches **512 tokens** or other trigger conditions are met.
-   **Automatic Flush**: When the buffer is full or remains idle for a certain period, Memobase automatically processes all buffered messages together.
-   **Manual Flush**: You can trigger immediate processing using the **Flush Buffer** tool in the Dify plugin.

#### When to Use Flush Buffer

-   **Testing & Debugging**: Use flush after conversations to see immediate results during development.
-   **Session End Detection**: Trigger flush when users leave the chat or close the session.
-   **Critical Updates**: When immediate memory processing is required for important information.

<Tip>Avoid flushing after every message as it increases token consumption significantly. Let Memobase handle automatic processing for optimal cost efficiency.</Tip>

### Example Workflows

#### Basic Memory Workflow

Here is a basic Dify workflow that uses the Memobase plugin to store and retrieve memory without immediate processing:

<Frame caption="A basic Dify workflow for memory storage and retrieval.">
  <img src="/images/dify_memobase_workflow.png" />
</Frame>

You can download the complete workflow file from: [memobase.yml](https://github.com/ACAne0320/dify-plugin-memobase/blob/main/_assets/memobase.yml)

This workflow is suitable for most production scenarios where automatic buffer processing is sufficient.

#### Memory Workflow with Buffer Flush

For scenarios requiring immediate memory processing (testing, debugging, or session-end detection), use this enhanced workflow:

<Frame caption="A Dify workflow with explicit buffer flush for immediate processing.">
  <img src="/images/dify_memobase_flush_workflow_example.png" />
</Frame>

You can download the complete workflow file from: [memobase_flush_workflow.yml](https://github.com/ACAne0320/dify-plugin-memobase/blob/main/_assets/memobase_flush_workflow.yml)

This workflow includes the **Flush Buffer** step to ensure conversation data is processed immediately. Use this pattern when:
-   You need to see memory updates right away during testing
-   The user is ending their session
-   You're storing critical information that must be available immediately

By integrating Memobase, you can build sophisticated AI applications that learn from and remember past interactions, leading to more engaging and personalized user experiences.